Custom Control – Calendar Date Control Walkthrough Example

Custom Control – CalendarDateControl Walkthrough Example

This example demonstrates a custom control plugin for Web Determinations; for more general information on constructing and debugging custom control plugins, see Create a Custom Control.

This example shows a calendar that is written in javascript to assist the user in selecting a date for an attribute input of a type that is a date in the question screen. The calendar looks like this:

 

The example custom control provider replaces any date input control where the custom property UseCalendarDateControl is set to True and the input type is set to Single Edit (Default).

It includes two re-usable abstract classes, InterviewControlWrapper and InputInterviewControlWrapper, which delegate as much as possible to the source control in the rule engine runtime layer, allowing the custom formatter to concentrate on special cases.

Construct the example

The custom control plugin is built using the following classes:

CalendarDateControlProvider

the class that Web Determinations will look for and load on startup. It can determine which rulebases or data sessions it wants to attach to; our example plugin will attach to anything. Our class will look for date controls with custom property UseCalendarDateControl that is set to True and the input type that is set to Single Edit (Default) and replace them by a custom control.

CalendarDateControl

the custom control itself. It is tightly coupled with the same-named CalendarDateControl.vm. The control and template work together to render the control and interpret the user input.

InterviewControlWrapper

an abstract convenience class which defers to the rule engine layer’s version of the control wherever it can, for all controls.

InputInterviewControlWrapper

an abstract convenience class for input controls, which adds methods to defer to the rule engine layer for input (attribute) controls.

The steps for building this custom control are:

  1. Copy the uncompiled rulebase .zip file found at examples\rulebases\source\HealthyEating.zip to a place on your machine where it can be unzipped and ready for use.
  2. Copy the CalendarDateControl.jar file found at examples\web-determinations\calendar-date-control to your rulebase’s plugins directory, where Oracle Web Determinations can find it. If your rulebase is at <…>\HealthyEating, the correct directory for your plugin is <…>\HealthyEating\Release\web-determinations\WEB-INF\classes\plugins. If the ‘Release’ directory does not exist, Build and Debug with screens once, to create it.
  3. Copy the velocity template file CalendarDateControl.vm from examples\web-determinations\calendar-date-control\src to your rulebase’s templates directory. If your rulebase is at <…>\HealthyEating, the correct location for your control template is <…>\HealthyEating\Release\web-determinations\WEB-INF\classes\templates\controls\CalendarDateControl.vm. The file name is important here – it must match the name of the custom control class exactly or the file will not be found.
  4. Copy the calendar javascript file calendar.vm from examples\web-determinations\calendar-date-control\src to your rulebase’s includes directory. If your rulebase is at <…>\HealthyEating, the correct location for your javascript file is <…>\HealthyEating\Release\web-determinations\WEB-INF\classes\templates\includes\calendar.vm.

    Note: The calendar javascript file was renamed to have a .vm extension because it will not be recognized by the velocity engine unless it has a .vm extension.

  5. Modify the velocity template for the question screen to include the calendar javascript file. If your rulebase is at <…>\HealthyEating, the velocity template for the question screen is located at <…>\HealthyEating\Release\web-determinations\WEB-INF\classes\templates\question_screen.vm.

    Locate the line where javascript-utilities.vm is used in the velocity template and add a reference for the calendar javascript file. The line to be inserted should have the format #parse(“includes/<javascript.vm>”). For this example, it should be #parse(“includes/calendar.vm”).

    The following is a sample modification:


    A modified velocity template file for the question screen is also found at examples\web-determinations\calendar-date-control\src\question_screen.vm, if you would like to replace your existing velocity template.

Customize the rulebase to use the plugin

The HealthyEating rulebase is already setup to use the plugin, but here are details on how to configure any rulebase that contains a date attribute input control to use it.

  1. In Oracle Policy Modeling, go to the File menu and select Project Properties…
  2. Add a new custom property definition for a control. Name the new custom property UseCalendarDateControl and change its data type to boolean; for example:



  3. Click OK to accept the custom property.
  4. Open the screen file that contains the Questions Screens folder
  5. Edit the date attribute input control found in the Question Screens folder. Make sure the input type is set to Single Edit(Default) and the custom property UseCalendarDateControl is set to True; for example:





  6. Click OK to accept the changes
  7. Save the changes and build and debug with screens. Your custom control should now be working:

Source Code

To view the source code for the CalendarDateControl sample, refer to examples\web-determinations\calendar-date-control in the Java runtime zip file.